package com.ddky.pophome.wight;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ddky.pophome.R;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IMeasurablePagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;

/**
 * description：
 * Author: 许少东
 * Created: 2/22/21 5:17 PM
 */
public class CustomHomeTabView extends RelativeLayout implements IPagerTitleView {
    protected int mSelectedColor;
    protected int mNormalColor;
    private TextView textView;

    public CustomHomeTabView(Context context) {
        super(context);
        RelativeLayout relativeLayout = new RelativeLayout(context);
        relativeLayout.setGravity(Gravity.CENTER);
        textView = new TextView(context);
        textView.setPadding(0,0,20,0);
        relativeLayout.addView(textView);
        textView.setGravity(Gravity.CENTER);
        RelativeLayout.LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams();
        layoutParams.rightMargin = 25;
        textView.setLayoutParams(layoutParams);
        removeAllViews();
        addView(relativeLayout);
        setGravity(Gravity.CENTER);
    }

    public int getSelectedColor() {
        return mSelectedColor;
    }

    public void setSelectedColor(int selectedColor) {
        mSelectedColor = selectedColor;
    }

    public int getNormalColor() {
        return mNormalColor;
    }

    public void setNormalColor(int normalColor) {
        mNormalColor = normalColor;
    }

    @Override
    public void onSelected(int index, int totalCount) {
//        textView.setTextColor(mSelectedColor);
        textView.setBackground(getResources().getDrawable(R.drawable.shape_home_tab_select_bg));
        textView.setTextColor(getResources().getColor(R.color.white));
    }

    @Override
    public void onDeselected(int index, int totalCount) {
//        textView.setTextColor(mNormalColor);
        textView.setBackground(getResources().getDrawable(R.drawable.shape_home_tab_normal_bg));
        textView.setTextColor(getResources().getColor(R.color.c_e94544));
    }

    @Override
    public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) {

    }

    @Override
    public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) {

    }

    public void setText(String text) {
        textView.setText(text);
    }
}
